package cn.lili.controller.user;

import cn.lili.common.utils.ResultUtil;
import cn.lili.common.vo.ResultMessage;
import cn.lili.modules.member.service.UserService;
import cn.lili.modules.member.service.VipService;
import cn.lili.modules.system.entity.dos.UserPageDto;
import cn.lili.modules.system.entity.dto.VipDto;
import cn.lili.modules.system.entity.dto.VipPageDto;
import cn.lili.modules.system.entity.vo.LiVipVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "会员管理")
@RequestMapping("/user/vip/manage")
public class VipController {
    /**
     * 会员管理
     */
    @Autowired
    private VipService vipService;
    @Autowired
    private UserService userService;

    @ApiModelProperty(value = "分页查询用户列表")
    @GetMapping("/pageList")
    public ResultMessage<Object> getPageList(UserPageDto dto){
        return userService.getUserNotVip(dto);
    }

    @ApiModelProperty(value = "会员分页查询")
    @GetMapping("/page")
    public ResultMessage<Object> vipPage(VipPageDto dto){

        return ResultUtil.data(vipService.pageFind(dto));
    }

    /**
     * 会员冻结
     * @param id
     * @return
     */
    @ApiModelProperty(value = "会员冻结")
    @GetMapping("/freeze")
    public ResultMessage<Object> freeze(@RequestParam String id){
        vipService.freeze(id);
        return ResultUtil.success();
    }

    @ApiModelProperty(value = "会员解冻")
    @GetMapping("/unfreeze")
    public ResultMessage<Object> unfreeze(@RequestParam String id){

        return vipService.unfreeze(id);
    }

    @ApiModelProperty(value = "会员添加")
    @PostMapping("/add")
    public ResultMessage<Object> addVip(@RequestBody VipDto dto){
       return vipService.add(dto);
    }

    @ApiModelProperty(value = "会员续费")
    @PutMapping("/extend")
    public ResultMessage<Object> vipExtend(@RequestBody VipDto dto){
       return vipService.vipExtend(dto);
    }
    /**
     * vip信息
     *
     * @return vip信息
     */
    @ApiModelProperty(value = "用户vip信息")
    @GetMapping("/getVipDetail")
    public ResultMessage<LiVipVo> getVipDetail() {
        return vipService.getVipDetail();
    }

    @ApiOperation(value = "根据激活码开通或续费会员")
    @ApiImplicitParam(name = "code", value = "激活码", required = true, dataType = "String", paramType = "path")
    @GetMapping(value = "/active/{code}")
    public ResultMessage<Object> activeVipByCode (@PathVariable String code) {
        vipService.activeVipByCode(code);
        return ResultUtil.success();
    }
}
